package cn.genmer.test.security.machinelearning.deeplearning4j.mnist.V2;

import cn.genmer.test.security.machinelearning.deeplearning4j.mnist.V1.MnistTrain;
import cn.genmer.test.security.machinelearning.deeplearning4j.mnist.V2.strategy.concrete.CnnStrategy;
import cn.genmer.test.security.machinelearning.deeplearning4j.mnist.V2.strategy.MnistModelStrategy;
import cn.genmer.test.security.machinelearning.deeplearning4j.mnist.V2.strategy.concrete.DaeStrategy;
import cn.genmer.test.security.machinelearning.deeplearning4j.mnist.V2.strategy.concrete.MlpStrategy;
import cn.genmer.test.security.machinelearning.deeplearning4j.mnist.common.ReadTextFile;
import org.nd4j.linalg.api.ndarray.INDArray;
/**
 * 初始解析卷积神经网络CNN
 */
public class MnistPredictV2 {
    public static void main(String[] args) throws Exception {
        // 加载预训练好的模型
        MnistModelStrategy predictor = new CnnStrategy();
//        MnistModelStrategy predictor = new MlpStrategy();
//        MnistModelStrategy predictor = new DaeStrategy();

        int imgNum = 25780;
        // 打印标记数据
        String label = ReadTextFile.readFileAsString(MnistTrain.BASE_PATH + "/mnist_png/decompression/" + imgNum +".txt");
        System.out.println("测试数据标记为：" + label);
        // 加载图片
        INDArray feature = predictor.loadImgAndGetFeature(MnistTrain.BASE_PATH + "/mnist_png/decompression/" + imgNum +".png");
        // 预测
        int prediction = predictor.predict(feature);
        System.out.println("模型预测结果为： " + prediction);
    }
}
 